package com.example.sangong.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

@Controller
@RequestMapping("/img")
public class ImgController {

    @GetMapping("/getPic")
    public void getPic(@RequestParam("path")String path,@RequestParam("picName") String picName, HttpServletResponse response) {
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path+"/" + picName); OutputStream out = response.getOutputStream()) {
            FileCopyUtils.copy(inputStream, out);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
